package com.kk.work05.controller;

import com.kk.work05.entity.Work05emp;
import com.kk.work05.service.Work05empService;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (Work05emp)表控制层
 *
 * @author makejava
 * @since 2025-04-30 21:23:58
 */
@RestController
@RequestMapping("work05emp")
public class Work05empController {
    /**
     * 服务对象
     */
    @Resource
    private Work05empService work05empService;

    /**
     * 分页查询
     *
     * @param work05emp   筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Work05emp>> queryByPage(Work05emp work05emp, PageRequest pageRequest) {
        return ResponseEntity.ok(this.work05empService.queryByPage(work05emp, pageRequest));
    }

    @GetMapping("deptId")
    public List<Work05emp> queryByDeptId(@RequestParam("deptId") Integer deptId) {
       return work05empService.queryByDeptId(deptId);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Work05emp> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.work05empService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param work05emp 实体
     * @return 新增结果
     */
    @PostMapping
    public int add(@RequestBody List<Work05emp> work05emp) {
       return work05empService.insert(work05emp);
    }

    /**
     * 编辑数据
     *
     * @param work05emp 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Work05emp> edit(Work05emp work05emp) {
        return ResponseEntity.ok(this.work05empService.update(work05emp));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.work05empService.deleteById(id));
    }

}

